﻿using System;
using System.IO;
using System.Reflection;
using System.Web;
using AnyOffice.Components;
using AnyOffice.general.knowledge;
using log4net;
namespace AnyOffice.general.knowledge
{
    public partial class uploaddisk : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            KnowledgeInfo knowledgeInfo = KnowledgeFactory.GetKnowledgeInfo();
            if ((knowledgeInfo != null) && knowledgeInfo.CanEdit)
            {
                string str = (Request.Form["attachment_id"] == null) ? "" : Request.Form["attachment_id"].ToString();
                HttpFileCollection files = Request.Files;
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile file = files[i];
                    if (files.GetKey(i).ToUpper() == "EDITFILE")
                    {
                        try
                        {
                            str = str.Replace("../", "");
                            str = str.Replace("/", @"\");
                            FileInfo info2 = new FileInfo(knowledgeInfo.DiskPath + str);
                            if (info2.Exists)
                            {
                                file.SaveAs(info2.FullName);
                                Response.Write("文件'" + info2.Name + "'保存成功！");
                            }
                            else
                            {
                                Response.Write("文件保存失败！");
                            }
                        }
                        catch (Exception exception)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("", exception);
                            }
                        }
                    }
                }
            }

        }
    }
}
